package com.example.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class ApplicationConf {

    //定义负载均衡策略
    @Bean
    public IRule ribbonRule() {
        return new RandomRule();
        /*可选策略：
        new RoundRobinRule();  //线性轮训
        new RetryRule();   //可以重试的轮训
        new WeightedResponseTimeRule();  //根据运行情况来计算权重
        new BestAvailableRule();  //过滤掉故障实例，选择请求数最小的实例
        new ZoneAvoidanceRule()； //根据server的zone区域和可用性来轮询选择
        */
    }


}
